<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '@/stores/pages/user'

const router = useRouter()
const userStore = useUserStore()

const goHome = () => {
  // 检查用户是否已认证
  if (userStore.isAuthenticated) {
    // 如果已认证，尝试跳转到仪表盘
    router.push('/app/dashboard').catch(err => {
      console.error('导航到仪表盘失败:', err)
      // 如果导航失败，跳转到登录页
      router.push('/auth/login')
    })
  } else {
    // 如果未认证，跳转到登录页
    router.push('/auth/login')
  }
}
</script>

<template>
  <div class="forbidden-container">
    <h1>403</h1>
    <p>访问被拒绝</p>
    <p>您没有权限访问此页面</p>
    <button @click="goHome">返回首页</button>
  </div>
</template>

<style scoped>
.forbidden-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

.forbidden-container h1 {
  font-size: 72px;
  margin-bottom: 20px;
  color: #e74c3c;
}

.forbidden-container p {
  font-size: 24px;
  margin-bottom: 15px;
  color: #333;
}

.forbidden-container button {
  font-size: 18px;
  color: #3498db;
  background-color: transparent;
  border: 1px solid #3498db;
  padding: 10px 20px;
  border-radius: 4px;
  transition: all 0.3s ease;
  margin-top: 20px;
  cursor: pointer;
}

.forbidden-container button:hover {
  background-color: #3498db;
  color: white;
}
</style>